package com.tinghua.mqTest.basices;


import com.rabbitmq.client.Channel;

import java.util.Scanner;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.MessageProperties;
import com.tinghua.mqTest.utils.ConnectionMQ;

import java.io.IOException;

public class Producer {
    public static final String QUEUE_NAME = "rabbitmq_01_test";

    public static void main(String[] args) throws IOException, TimeoutException{
        Channel channel = ConnectionMQ.utilConnectionMQ();
        boolean durable = true;
        channel.queueDeclare(QUEUE_NAME, durable, false, false, null);

        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            System.out.print("发送一个消息:");
            String msg = sc.next();
            channel.basicPublish("", QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, msg.getBytes());
        }
    }
}
